import java.util.concurrent.CountDownLatch;

import com.fourinone.BeanContext;
import com.fourinone.CoolHashClient;
import com.fourinone.CoolHashException;


public class EasyCoolHashDemo {

    
    public static void main(String[] args){
        long start = System.currentTimeMillis();
        CountDownLatch latch = new CountDownLatch(100);
        for (int j = 0; j < 100;j++){
          new Thread(  new Worker(j, latch)).start();
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(System.currentTimeMillis() - start);
    }
    private static class Worker implements  Runnable {

        private int index;
        private CountDownLatch latch;
        
        public Worker(int index,CountDownLatch latch){
            this.index = index;
            this.latch = latch;
        }
        @Override
        public void run() {
            CoolHashClient chc = BeanContext.getCoolHashClient("localhost",2014);
            for(int i = 0; i < 10000; i++){
                try {
                    chc.put("k_" +index + "_" + i , "xxxxxxxxxxxxxx");
                } catch (CoolHashException e) {
                    e.printStackTrace();
                }
            }
            latch.countDown();
        }
        
        
    }
}
